//
//  SINATecManagerSignDetaileViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/10.
//  Copyright © 2018年  androidlongs. All rights reserved.
//  未签到详情页面
//  签到详情页面

#import "SINATecManagerSignDetaileViewController.h"
#import "SINATecCourseSignModel.h"
#import "SINATecManagerCourseSignItemTableViewCell.h"

@interface SINATecManagerSignDetaileViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *userTitleLabel;
@property (weak, nonatomic) IBOutlet UITableView *contentView;

@property(nonatomic,strong) NSMutableArray *dataList;

@end

@implementation SINATecManagerSignDetaileViewController

-(NSMutableArray *)dataList{
    if (!_dataList) {
        _dataList = [NSMutableArray array];
    }
    return  _dataList;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"未签到详情";
    [super initBackItem];
    self.contentView.delegate=self;
    self.contentView.dataSource=self;
    self.contentView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.contentView.backgroundColor=[UIColor colorWithHexString:@"#fafafa"];
    self.contentView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.contentView.showsVerticalScrollIndicator=NO;
    self.contentView.showsHorizontalScrollIndicator=NO;
    for (NSInteger i=0; i<0; i++) {
        SINATecCourseSignModel *model = [[SINATecCourseSignModel alloc]init];
        model.courseTitle=@"中国古代史导论";
        model.courseTime=@"2017年12月31日";
        [self.dataList addObject:model];
    }
    
    [self.contentView reloadData];
    
    if (self.schoolYearModel!=nil) {
        [self loadingSchoolYearSubClassListNetData];
        DLog(@"%@ %@ %@未签到情况" ,self.schoolYearModel.schoolyear,self.schoolYearModel.term,self.courseModel.realname);
        
        self.userTitleLabel.text=[NSString stringWithFormat:@"%@ %@ %@未签到情况",self.courseModel.realname,self.schoolYearModel.schoolyear,self.schoolYearModel.term];
    }else{
        [self loadingSchoolYearSubClassListNetData];
        DLog(@"%@ %@ %@未签到情况" ,self.courseModel.schoolyear,self.courseModel.term,self.courseModel.realname);
        
        self.userTitleLabel.text=[NSString stringWithFormat:@"%@ %@ %@未签到情况",self.courseModel.realname,self.courseModel.schoolyear,self.courseModel.term];
    }
    
   
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataList.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    SINATecManagerCourseSignItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SINATecManagerCourseSignItemTableViewCell"];
    
    if (cell == nil) {
        cell= [[[NSBundle mainBundle]loadNibNamed:@"SINATecManagerCourseSignItemTableViewCell" owner:nil options:nil] firstObject];
        
    }
    SINATecCourseModel *model = self.dataList[indexPath.row];
    cell.model=model;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


//加载未签到详情
-(void)loadingSchoolYearSubClassListNetData{
    
  
    
    if (self.schoolYearModel==nil&&self.courseModel.schoolyear==nil) {
        [YPXToastView showToastViewWithText:@"暂无学年信息" andDuration:2 andParentView:self.view];
        return;
    }
   
    [self startLoading];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    
    if (self.schoolYearModel!=nil) {
        //班级id String classifyid
        [dict setObject:self.subClassModel.classifyid forKey:@"classifyid"];
        //学年 String schoolyear
        [dict setObject:self.schoolYearModel.schoolyear forKey:@"schoolyear"];
        //学期 String term
        [dict setObject:self.schoolYearModel.term forKey:@"term"];
        //用户的uuid String studentuuid
        [dict setObject:self.courseModel.uuid forKey:@"studentuuid"];
        //科目id String subjectid
        [dict setObject:self.model.courseId forKey:@"subjectid"];
        
    }else{
        
        /*
         {
         "lessonperiod": 150,
         "signcnt": 3,
         "schoolyear": "2017 - 2018",
         "term": "上半学期",
         "realname": "赵七"
         },
         */
        
        //班级id String classifyid
        [dict setObject:self.courseModel.lessonperiod forKey:@"classifyid"];
        //学年 String schoolyear
        [dict setObject:self.courseModel.schoolyear forKey:@"schoolyear"];
        //学期 String term
        [dict setObject:self.courseModel.term forKey:@"term"];
        //用户的uuid String studentuuid
        [dict setObject:self.courseModel.uuid forKey:@"studentuuid"];
        //科目id String subjectid
        [dict setObject:self.courseModel.courseId forKey:@"subjectid"];
    }
    
    
    
    [self.dataList removeAllObjects];
    WeakSelf;
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@",baseUrl,getSignByUserAndSubjectOrClassifyInfoUrl] withParamters:dict success:^(id responseData) {
        [weakSelf stopLoading];
        NSString *code = responseData[@"code"];
        
        if ([code isEqualToString:@"1000"]) {
            NSArray *result = responseData[@"content"];
            if (result==nil||result.count==0) {
               
            } else {
                //有班级信息
                for(NSInteger i=0;i<result.count;i++){
                    NSDictionary *dic = result[i];
                    
                    SINATecCourseModel *model = [[SINATecCourseModel alloc]initWithDict:dic];
                    [self.dataList addObject:model];
                    
                }
              
                [self.contentView reloadData];
            }
            
            
        }else{
            
            NSString *message =responseData[@"message"];
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
                                                                 cancleBtn:nil];
            [alertView showXLAlertView];
            
            
        }
        
        
        
        
        
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"加载 失败  %@ ",error.debugDescription);
        [weakSelf stopLoading];
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"加载数据失败" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        
    }];
}
@end
